<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>我要提现</title>
    <link rel="stylesheet" href="../../css/mui.min.css" />
    <link rel="stylesheet" href="../../css/own.css" />
    <script type="text/javascript" src="../../js/mui.min.js" ></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script src="../../js/jquery-1.11.3.js"></script>
	<script>
		mui.init({
//		    subpages:[{
//		      url:'../commonback.html',
//		      id:'common.html',
//		      styles:{
//		        top:'0px',//mui标题栏默认高度为45px；
//		      }
//		    }]
		  });   
		var Certification=false;
		var balance=null;
		var drawHandleFee=null;
		var SetDrawPwd=false;
		var freeCashMoney = null;
		mui.plusReady(function(){
			  
    		//初始化监听头部和底部事件
			tzdr.init.initHearListener();
    		document.getElementById("bindBankCard").addEventListener("tap",function(){
    			bindBankcard();
    		});
    		document.getElementById("bank_info").addEventListener("tap",function(){
    			bindBankcard();
    		});
      		document.getElementById("modifyPassword").addEventListener("tap",function(){
	    				//打开设置提现密码页面
	    				mui.openWindow("withdcode.html");
    				});
    		document.getElementById("drawmoneysub").addEventListener("tap",function(){
    			drawmoneySubmit();
    		});
    		//获取默认绑定的银行卡信息
    		var paramUrl={
						url:"../login/login.html"
					}
    		mui.app_request("user/withdraw/bank_list",{},
    		function(result){
    			if(!mui.isnull(result.data)){
    				mui.each(result.data,function(i){
    					if(result.data[i].default){
    						setbankinfo(result.data[i]);
    					}
    				});
    			}
    			
    		},function(result){
    			if(result.code==3){
    				mui.toast("用户信息不存在！");
    				return;
    			}else if(result.code==2){
    				mui.toast("获取失败");
    				return;
    			}
    		},paramUrl);
    		//去后台接口校验是否实名认证
			mui.app_request("/user/getbalancerate",{
				"businessType":4 
			},function(result){
				balance=document.getElementById("balance");
				drawHandleFee=document.getElementById("drawHandleFee");
				freeCashMoney = document.getElementById("freeCashMoney");
				//是否实名
				if(result.data.isCertification){
					Certification=true;
				}
				if(!mui.isnull(result.data.balance)){
					balance.innerHTML=result.data.balance;
				}else{
					balance.innerHTML="0.00";
				}
				
				if(!mui.isnull(result.data.drawHandleFee)){
					drawHandleFee.innerHTML=result.data.drawHandleFee;
				}else{
					drawHandleFee.innerHTML="0.00";
				}
				if(!mui.isnull(result.data.operateMoney)){
					freeCashMoney.innerHTML=result.data.operateMoney;
				}else{
					freeCashMoney.innerHTML="0.00";
				}
				//是否设置了提现密码
				if(result.data.isSetDrawPwd){
					SetDrawPwd=true;
					document.getElementById("drawpassword").placeholder="输入密码";
					document.getElementById("drawpassword").removeAttribute("readonly");
					$("#modifyPassword").css("display","block");
				}else{
					$("#modifyPassword").css("display","block");
					document.getElementById("drawpassword").placeholder="未设置提现密码";
					document.getElementById("drawpassword").setAttribute("readonly","readonly");
				}
			},function(result){
				return;
			});
		});
		
		
		function drawMoney(){
			var drawmoney=document.getElementById("drawmoney").value;
			var paramUrl={
						url:"../login/login.html"
					}
			if(mui.isnull(drawmoney)){
				document.getElementById("drawmoney").value="";
				mui.toast("不能输入非法字符");
				return;
			}
			if(drawmoney > parseFloat($("#balance").text())){
				mui.toast("账户余额不足");
				return;
			}
			mui.app_request("user/withdraw/drawFee",{
				"money":drawmoney
			},function(result){
				var message = result.data.fee;
				$("#drawHandleFee").text(message);
				if(!isNaN(message)){
					$("#draw_time").text(drawmoney - message);
				}
				return;
			},function(result){
				mui.toast(result.message);
				return;
			},paramUrl) 
			/*var drawmoney=document.getElementById("drawmoney").value;
			var balance=document.getElementById("balance").innerHTML;
			var drawHandleFee=document.getElementById("drawHandleFee");
			
			if(mui.isnull(drawmoney)){
				document.getElementById("drawmoney").value="";
				mui.toast("不能输入非法字符");
				return;
			}
			if(mui.isnull(balance)){
				mui.toast("余额不足，请充值！");
				return;
			}
			
			if(!tzdr.moneyUtils.testDecimal(drawmoney)){
				mui.toast("最多输入小数点后两位");
				document.getElementById("drawmoney").value="";
				document.getElementById("draw_time").innerHTML="0";
				return;
			}
			var draw_time= balance - drawmoney ;
			var iscould= draw_time >= 0 ? true : false;
			if(iscould){
				drawHandleFee.innerHTML=tzdr.moneyUtils.decimal(drawmoney*0.01,2);
				document.getElementById("draw_time").innerHTML=tzdr.moneyUtils.decimal(drawmoney-drawHandleFee.innerHTML,2);
			}else{
				mui.toast("余额不足，请充值！");
				return;
			}*/
			
		};
		
		var abbreviation=null;
		var card=null;
		function setbankinfo(bank){
			var bank_info=document.getElementById("bank_info");
			bank_info.setAttribute("style","display: block;");
			document.getElementById("defult").setAttribute("style","display: none;");
			var a=document.createElement("a");
			a.setAttribute("class","mui-navigate-right");
			var img=document.createElement("img");
			abbreviation=bank.abbreviation;
			img.setAttribute("src","../../images/bank/"+bank.abbreviation+".png");
			var h3=document.createElement("h3");
			h3.innerText=bank.bankName;
			var p=document.createElement("p");
			p.innerText=bank.card;
			card=bank.card;
			
			a.appendChild(h3);
			a.appendChild(p);
			a.appendChild(img);
			bank_info.appendChild(a);
		}
		
		
		

		function bindBankcard(){
			
			if(!Certification){
				plus.nativeUI.confirm("请先进行实名认证",function(e){
					if(e.index==1){
						mui.openWindow({url:"verified.html",id:"verified",extras:{backPage:'withdraw'}});
					}else if(e.index==0){
						mui.openWindow("withdraw.html","withdraw");
					}
				},"提示",['取消','去认证']);
			return;
			}
			
			//去绑定银行卡
			mui.openWindow("bankcode.html","bankcode");
		}
		
		//确认提现
		function drawmoneySubmit(){
			var bank_info=document.getElementById("bank_info").style.display;
			var drawpassword=document.getElementById("drawpassword").value;
			var drawmoney=document.getElementById("drawmoney").value;
			var defult=document.getElementById("defult").style.display;
			var paramUrl={
						url:"../login/login.html"
					}
			if(bank_info=="none"&&defult=="block"){
				mui.toast("请绑定银行卡");
				return;
			}
			if(!SetDrawPwd){
				mui.toast("请设置提现密码");
				return;
			}
			
			if(mui.isnull(drawpassword)){
				mui.toast("请输入提现密码");
				return;
			}
			if(mui.isnull(abbreviation)||mui.isnull(card)){
				mui.toast("请绑定银行卡");
				return;
			}
			if(mui.isnull(drawmoney)){
				mui.toast("提现金额不能为空");
				return;
			}
			mui.app_request("user/withdraw/handle",{
				"bank":abbreviation,
				"card":card,
			   "money":drawmoney,
			   "withdrawPwd":drawpassword
			},function(result){
				mui.toast("提交成功，系统会尽快处理！");
				document.getElementById("drawmoney").value="";
				document.getElementById("drawmoney").placeholder="输入金额";
				setTimeout(function(){
					location.reload(true);
				},1500);
				return;
			},function(result){
				if(result.code==0){
					mui.toast("token失效");
					return;
				}else if(result.code==2){
					mui.toast("提现失败");
					return;
				}else if(result.code==3){
					mui.toast("用户信息不存在");
					return;
				}else if(result.code==4){
					mui.toast("银行卡卡号不存在");
					return;
				}else if(result.code==5){
					mui.toast("你的账户已被限制提现，具体原因为："+result.message+",请联系客服解除限制！");
					return;
				}else if(result.code==6){
					mui.toast("系统升级期间无法提现");
					return;
				}else if(result.code==7){
					mui.toast("余额不足不能提现");
					return;
				}else if(result.code==8){
					mui.toast("当天取款次数不能超过5次");
					return;
				}else if(result.code==9){
					mui.toast("每次提现金额不能小于10元");
					return;
				}else if(result.code==10){
					mui.toast("提现密码错误");
					return;
				}else if(result.code==11){
					mui.toast("网银平台暂不支持此银行提现，请重新添加银行！");
					return;
				}else if(result.code==12){
					mui.toast("网银限制，单笔提现金额不能超过50000元，每天可提现5笔。");
					return;
				}else if(result.code==13){
					mui.toast("未实名认证");
					return;
				}
				
			},paramUrl)
			
		};
		
	</script>

</head>
<body>

	<header class="mui-bar mui-bar-nav own-topbg">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back"><i>返回</i></a>
		<h1 id="nav-title" class="mui-title">我要提现</h1>
		<a href="javascript:void(0);" class="top-tel" id="online">在线客服</a>
	</header>
	<div class="mui-content ac_tel">
		<ul class="mui-table-view aw_bank">
			<li class="mui-table-view-cell" style="display: none;" id="bank_info">
				<!--<a class="mui-navigate-right" href="javascript:void(0);">
					<img src="../../images/icbc.gif" />
					<h3>中国工商银行</h3>
					<p>6222023100061111111</p>
				</a>-->
			</li>
			<li class="mui-table-view-cell" id="defult">
				<a class="mui-navigate-right" id="bindBankCard">
					<img src="../../images/ac_code.gif" />
					<label>未绑定银行卡</label>
				</a>
			</li>
		</ul>
		<ul class="mui-table-view aw_withlist">
			<li class="mui-table-view-cell">
				<label>账户余额</label>
				<span><i id="balance"></i>元</span>
			</li>
		</ul>	
		<p id="freeMoney"><span>累计免提现手续费金额为：</span><span class="freeCashMoneyColor"><i id="freeCashMoney">0.00</i>元</span></p>	
		<ul class="mui-table-view aw_withlist">	
			<li class="mui-table-view-cell">
				<label>提现金额</label>
				<span>元</span>
				<input id="drawmoney" type="number" class="mui-input-clear" placeholder="输入金额" data-input-clear="5" oninput="drawMoney()">
			</li>
			<li class="mui-table-view-cell">
				<label>提现手续费</label>
				<span><i id="drawHandleFee"></i>元</span>
			</li>
			<li class="mui-table-view-cell">
				<label>实际到账</label>
				<span><i id="draw_time"></i>元</span>
			</li>
		<!--</ul>-->
		<!--<ul class="mui-table-view aw_withpassword">-->
			<li class="mui-table-view-cell">		 		
				<!--<a class="mui-navigate-right" href="javascript:void(0);">-->
					<div class="mui-input-row mui-password">
						<label class="loginPassword">提现密码</label>
						<input id="drawpassword" type="password" class="mui-input-password" placeholder="请输入密码" autocomplete="off" onkeyup="value=value.replace(/[\W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
					</div>
					<!--<label>提现密码</label>
					<input  id="drawpassword" type="password" class="mui-input-clear" placeholder="输入密码" data-input-clear="5" >
					<b class="aw_withpasslink" id="drawPage"></b>-->
				<!--</a>-->
			</li>
			<!--<li class="mui-table-view-cell">		 		
				<label>免费提现金额</label>
					<span><i >123</i>元</span>
			</li>-->
			<!--<li class="mui-table-view-cell" id="changePwd">		 		
				<a class="mui-navigate-right" href="javascript:void(0);">
					<label>修改提现密码</label>
					<input  id="" type="password" class="mui-input-clear" placeholder="修改提现密码" data-input-clear="5" readonly="readonly">
					<b class="aw_withpasslink" id="drawPage"></b>
				</a>
			</li>-->
		</ul>
		<!--<input type="text" oninput="insertContent()" id="content1" />
		<span id="content"></span>-->
		<a id="modifyPassword">设置/修改提现密码</a>
		<div class="ac_btn">
			<button id="drawmoneysub" type="button" class="mui-btn mui-btn-block lg-btnlogin">确认提现</button>								
		</div>	
		
		<div class="mui-content-padded">
			<h5>温馨提示：</h5>
			<p>1、到账时间：工作日09：00——16:30申请，24小时内到账，最快5分钟到账。其余时间申请，将在下一个工作日到账。</p>
			<p>2、提现手续费 ：</p>
			<p class="bottomTip">1%（适用于充值后，未实际操盘金额）。</p>
			<p class="bottomTip">0元（适用于操盘用户提现）。</p>
			<p style="margin-top: 10px;">3、提现处理时间：每个工作日固定时间进行提现处理。具体为10：00、14：00、16：00、17：30。</p>
		</div>
	</div>
	<script>
		tzdr.online();
//		function insertContent(){
//			
//			var s=document.getElementById("content1").value;
//			document.getElementById("content").innerText=s;
//		}
	</script>
</body>
</html>
